import request from '@/utils/request';
import { hasIsSw,isCustome,isLianxiSite,isCustomeSubject} from '../utils/utils';;
import { baseurl } from "./baseurl";
export interface getStudentSubjectParams {
  uid: string;
}
export async function getStudentSubject(params: getStudentSubjectParams) {
  /* 获取学生专业 */
  const data = new FormData();
  data.append('uid', params.uid);
  const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
  if(hasIsSw()){
    data.append('is_sw',is_sw);
  }
  return request(`${baseurl}index/index/online_exercise`, {
    method: 'POST',
    data,
  });
}


export interface getTestPaperParams {
    type: string;
    subject: any;
    p_type: string;
    uid: string;
    wrongs:string
  }
  
  export async function getTestPaper(params: getTestPaperParams) {
    /* 获取试题 */
    const data = new FormData();
    data.append('subject', params.subject);
    data.append('type', params.type);
    data.append('p_type', params.p_type);
    data.append('uid', params.uid);
    data.append('wrongs', params.wrongs);
    const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
    if(hasIsSw()){
      data.append('is_sw',is_sw);
    }
    if(isCustome()&&isCustomeSubject(params.subject)){
      return request(`${baseurl}index/index/exercise_optional`, {
        method: 'POST',
        data,
      });
    }
    return request(`${baseurl}index/index/exercise`, {
      method: 'POST',
      data,
    });
  }
  

  export interface submitPracticePaperParams {
    allIds: any;
    uid: string;
    wrongAnswers: any;
    correctAnswers:any;
    marked:any;
    rightAnswers:any;
    all:any
    type:any
    subject:any;
    wrong_num:any;
    wrong_done:any;
    wrong_done_right:any;
    right_num:any;
    time:any;
    complete:any;
    id:any;
  }
  
  export async function submitPracticePaper(params: submitPracticePaperParams) {
    /* 提交练习 */
    const data = new FormData();
    data.append('wrongAnswers', params.wrongAnswers);
    data.append('uid', params.uid);
    data.append('allIds', params.allIds);
    data.append('done_num', params.correctAnswers.length);
    data.append('marked', params.marked);
    data.append('rightAnswers', params.rightAnswers);
    data.append('type', params.type);
    data.append('all', params.all);
    data.append('subject', params.subject);
    data.append('wrong_num', params.wrong_num);
    data.append('wrong_done', params.wrong_done);
    data.append('wrong_done_right', params.wrong_done_right);
    data.append('right_num', params.right_num);
    data.append('time', params.time);
    data.append('complete', params.complete);
    data.append('id', params.id);

    const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
    if(hasIsSw()){
      data.append('is_sw',is_sw);
    }
    return request(`${baseurl}index/index/exercise_examination`, {
      method: 'POST',
      data,
    });
  }

  export async function saveWrongOrMarkedQuestions(params) {
    /* 存储错题 */
    const data = new FormData();
    data.append('wrong_done', params.wrongAnswers);
    data.append('id', params.id);
    const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
    if(hasIsSw()){
      data.append('is_sw',is_sw);
    }
    return request(`${baseurl}index/index/storage`, {
      method: 'POST',
      data,
    });
  }
  
  
  export interface getTestNumParams {
    type: string;
    subject: any;
    p_type: string;
    uid: string;
  }
  
  export async function getTestNum(params: getTestNumParams) {
    /* 获取试题 */
    const data = new FormData();
    data.append('subject', params.subject);
    data.append('type', params.type);
    data.append('p_type', params.p_type);
    data.append('uid', params.uid);
    const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
    if(hasIsSw()){
      data.append('is_sw',is_sw);
    }
    if(isCustome()&&isCustomeSubject(params.subject)){
      return request(`${baseurl}index/index/exercise_num_optional`, {
        method: 'POST',
        data,
      });
    }
    return request(`${baseurl}index/index/exercise_num`, {
      method: 'POST',
      data,
    });
  }
    
  export async function clearRecord(params:any) {
    /* 清除记录 */
    const data = new FormData();
    data.append('uid', params.uid);
    data.append('subject', params.subject);
    const is_sw = JSON.parse((localStorage.getItem('userinfo')||'')).is_sw;
    if(hasIsSw()){
      data.append('is_sw',is_sw);
    }
    return request(`${baseurl}index/index/eliminate`, {
      method: 'POST',
      data,
    });
  }  